﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Traceability.App.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UpLoadController : ControllerBase
    {
        public UpLoadController(IWebHostEnvironment web)
        {
            Web = web;
        }
        public IWebHostEnvironment Web { get; }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpFile(IFormFile file) 
        {
            string t = file.ContentType;
            string path = Directory.GetCurrentDirectory() + "/wwwroot/pic/" + file.FileName;
            using (FileStream fs = new FileStream(path, FileMode.Create)) 
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            return Ok("http://localhost:5045/pic/" + file.FileName);
        }

        
    }
}
